package cn.mysdp.biz.facade;

import cn.mysdp.utils.JavaBeansUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @ClassName:
 * @Description:
 * @Author: SDP
 * @Date: 2021-10-30
 * @Version: 1.0
 * Table:
 * Comment:
 *
 */
@Component
public class LaunchBrowserFacadeImpl implements ApplicationRunner {
    @Value("${server.port}")
    String serverPort;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        String url = "http://localhost:" + serverPort+"?random="+(new Date()).getTime()+"#/sdp_workspace";
        try {
            System.out.println(System.getProperty("os.name"));
            if (JavaBeansUtil.isWindows()) {
                Runtime.getRuntime().exec("cmd /c start " + url);
            } else if (JavaBeansUtil.isMac()) {
                Runtime.getRuntime().exec("open -a Safari " + url);
            } else if (JavaBeansUtil.isLinus()) {
                Runtime.getRuntime().exec("browser " + url);
            }
        }catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}